﻿using SqlSugar;
using System;
using System.Collections.Generic;

namespace LD
{
    [SugarIndex("TB_Product_barcode", "Barcode", OrderByType.Asc)]
    public class TB_Product
    {
        [SugarColumn(IsPrimaryKey = true)]
        public string Pid { get; set; }
        /// <summary>
        /// 条码（产品序列号）
        /// </summary>
        public string Barcode { get; set; }
        [SugarColumn(IsNullable = true)]
        public string Line { get; set; }
        /// <summary>
        /// 设置（如：ANSI）
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string Config { get; set; }

        /// <summary>
        /// 群组 如：X2966-M
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string Group { get; set; }

        /// <summary>
        /// 夹具名称
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string FixtureName { get; set; }
        /// <summary>
        /// CT
        /// </summary>
        public double CycleTime
        {
            get
            {
                return Math.Round((EndTime - StartTime).Value.TotalSeconds, 3);
            }
        }
        /// <summary>
        /// 当前产品结果
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string Result { get; set; }
        /// <summary>
        /// CCD拍照结果，例：OK
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string CCD_Result { get; set; }
        /// <summary>
        /// 扭矩结果，例：OK
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string Torque_Result { get; set; }
        /// <summary>
        /// 角度结果,例：OK
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string Angle_Result { get; set; }
        /// <summary>
        /// 累计结果,例：ok
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string Accumulative_Result { get; set; }
        /// <summary>
        /// 产品开始时间
        /// </summary>
        public DateTime StartTime { get; set; } = DateTime.Now;

        /// <summary>
        /// 产品结束时间
        /// </summary>
        public DateTime? EndTime { get; set; }
        /// <summary>
        /// 产品备注
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string Remark { get; set; }
        /// <summary>
        /// NG原因
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string NgReason { get; set; }
        /// <summary>
        /// NG编号
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string NgScrewNo { get; set; }
        /// <summary>
        /// 真空异常次数
        /// </summary>
        public int VacAlarm { get; set; }
        /// <summary>
        /// 抛料异常次数
        /// </summary>
        public int TossingScrew { get; set; }
        /// <summary>
        /// CT(做一个产品划分时间自动计算也叫周期时间)
        /// </summary>
        public double CT
        {
            get
            {
                return Math.Round((EndTime - StartTime).Value.TotalSeconds, 3);
            }
        }
        public bool HiveSuccess { get; set; }
        public TB_Product Clone()
        {
            return this.MemberwiseClone() as TB_Product;
        }

        /// <summary>
        /// 产品绑定的螺丝（集合）
        /// </summary>
        [Navigate(NavigateType.OneToMany, nameof(TB_Screw.Pid))]
        public List<TB_Screw> ScrewDatas { get; set; }
    }
}
